package annomation;

import java.lang.reflect.Method;

@Pro(className = "annomation.Apple",methodName = "displayName")
public class ReflectPro {
    public static void main(String[] args) {
        //1.1获取该类的字节码文件对象
        Class<ReflectPro> reflectProClass= ReflectPro.class;
        //1.2获取上边的注解对象
        Pro an=reflectProClass.getAnnotation(Pro.class);
        //1.3调用注解对象中定义的抽象方法，获取返回值；
        String className=an.className();
        String methodName=an.methodName();
        System.out.println(className);
        System.out.println(methodName);

        //3.加载该类进入内存
        Class cls= null;
        try {
            cls = Class.forName(className);
            //4.创建对象
            Object obj=cls.newInstance();
            //5.获取方法对象
            Method method=cls.getMethod(methodName);
            //6.执行方法
            method.invoke(obj);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
